package com.yiduan.apollocrm.views.mediators
{
	import com.yiduan.apollocrm.models.Contact;
	import com.yiduan.apollocrm.models.Contract;
	import com.yiduan.apollocrm.views.ContractsView;
	import com.yiduan.apollocrm.views.NewOrEditContractView;
	
	import flash.events.Event;
	import flash.events.MouseEvent;
	
	import mx.collections.ArrayCollection;
	import mx.resources.ResourceManager;
	
	import org.robotlegs.mvcs.Mediator;
	
	public class ContractsMediator extends Mediator
	{
		[Inject]
		public var contractsView:ContractsView;		
		
		public function ContractsMediator() {
			super();
		}
		
		override public function onRegister():void {
			getContractList();
			contractsView.newContractBtn.addEventListener(MouseEvent.CLICK, newContractHandler);
		}
		
		private function newContractHandler(e:Event):void {
			contractsView.navigator.pushView(NewOrEditContractView);
		}
		
		private function getContractList():void {
			var contractCollection:ArrayCollection = new ArrayCollection();
			var contract1:Contract = new Contract();
			contract1.description = "合同1";
			contractCollection.addItem(contract1);
			var contract2:Contract = new Contract();
			contract2.description = "合同2";
			contractCollection.addItem(contract2);
			var contract3:Contract = new Contract();
			contract3.description = "合同3";
			contractCollection.addItem(contract3);
			var contract4:Contract = new Contract();
			contract4.description = "合同4";
			contractCollection.addItem(contract4);
			var contract5:Contract = new Contract();
			contract5.description = "合同5";
			contractCollection.addItem(contract5);
			contractsView.contractList.dataProvider = contractCollection;
		}
		
	}
}